<!--
 * @Description:弹出拖动框
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-20 09:50:12
 -->
<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>拖动弹出框</title>
	<style>
		* {
			margin: 0;
			padding: 0
		}

		.nav {
			height: 30px;
			background: #036663;
			border-bottom: 1px solid #369;
			line-height: 30px;
			padding-left: 30px;
		}

		.nav a {
			color: #fff;
			text-align: center;
			font-size: 14px;
			text-decoration: none;
		}

		.d-box {
			width: 400px;
			height: 300px;
			border: 5px solid #eee;
			box-shadow: 2px 2px 2px #666;
			position: absolute;
			top: 50%;
			left: 50%;
			margin-top: -155px;
			margin-left: -205px;
			/* display: none; */
		}

		.hd {
			width: 100%;
			height: 25px;
			background-color: #7c9299;
			border-bottom: 1px solid #369;
			line-height: 25px;
			color: white;
			cursor: move;
		}

		#box_close {
			float: right;
			cursor: pointer;
		}
	</style>
	<script>
		window.onload = function () {
			let box = document.getElementById("d_box")
			let drop = document.getElementById("drop")
			//鼠标放在 drop 但是移动的是 box
			startDrop(drop, box)

			function startDrop(current, move) {
				current.onmousedown = function (event) {
					var event = event || window.event
					var x = event.clientX - move.offsetLeft-205; //拖动块固定到左边的距离
					var y = event.clientY - move.offsetTop-155; //拖动块固定到左边的距离
					document.onmousemove = function (event) { //拖动
						var event = event || window.event
						move.style.left = event.clientX - x + "px"; //拖动块在父级游走的距离
						move.style.top = event.clientY - y + "px"; //拖动块在父级游走的距离
					}
				}
				document.onmouseup = function (event) { //弹起
					document.onmousemove = null
				}
				
			}

			// let demo = document.getElementById("deom")
			// var bar = scrollBar.children[0]
			// var mask = scrollBar.children[1]


		}
	</script>
</head>

<body>
	<div class="nav">
		<a href="javascript:;" id="register">注册信息</a>
	</div>
	<div class="d-box" id="d_box">
		<div class="hd" id="drop">
			注册信息(可以拖拽)
			<div id="box_close">[关闭]</div>
		</div>
	</div>
</body>

</html>